package dfs;

import java.util.ArrayList;
import java.util.List;

public class 串联字符串的最大长度 {
    public static void main(String[] args) {
        List<String> arr= new ArrayList<>();
        arr.add("un");
        arr.add("iq");
        arr.add("ue");
        System.out.println(maxLength(arr));
    }
    static int ans=0;
    public static int maxLength(List<String> arr) {
         if (arr==null || arr.size()==0)
             return 0;
        dfs(arr,0,new StringBuilder());
        return ans;
    }
    private static void dfs(List<String> arr, int index, StringBuilder builder) {
        if (!method(builder.toString()))
            return;
        ans=Math.max(ans,builder.length());
        for (int i = index; i < arr.size(); i++) {
            String s = arr.get(i);
            builder.append(s);
            dfs(arr,i+1,builder);
            builder.delete(builder.length()-s.length(),builder.length());
        }
    }
    //判断字符串中是否有重复字母
    public static boolean method(String s){
        int[] ints = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            ints[c-'a']++;
            if (ints[c-'a']>1)
                return false;
        }
        return true;
    }
}
